package com.smarth.zhizulian.utils;


import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

/**
 * Created by KUMA on 2016/11/29.
 */
public class GsonUtils {
    private static Gson gson = new GsonBuilder().create();

    private static Gson gsonWithoutExpose = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();

    public static <T> T fromJson(String json, Class<T> clazz) {
        return gson.fromJson(json, clazz);
    }

    public static <T> T fromJson(String json, TypeToken<T> type) {
        return gson.fromJson(json, type.getType());
    }

    public static <T> T fromJsonWithoutExpose(String json, Class<T> clazz) {
        return gsonWithoutExpose.fromJson(json, clazz);
    }

    public static <T> T fromJsonWithoutExpose(String json, TypeToken<T> type) {
        return gsonWithoutExpose.fromJson(json, type.getType());
    }

    public static String toJson(Object object) {
        return gson.toJson(object);
    }
}
